解除R中从github上下载包API限制的问题(Error: Failed to install ‘unknown package‘ from GitHub: HTTP error 403. )

您所在的位置:网站首页 ubuntu 184 download 解除R中从github上下载包API限制的问题(Error: Failed to install ‘unknown package‘ from GitHub: HTTP error 403. )

解除R中从github上下载包API限制的问题(Error: Failed to install ‘unknown package‘ from GitHub: HTTP error 403. )

2023-08-15 06:33| 来源: 网络整理| 查看: 265

最近在github上下载包,出现了API下载速率限制的问题,返回error 403,并要求使用github_token()取消api rate 的限制。这是因为github会扫描需要安装的依赖程序,如果数目超过他的api rate,github就会限制下载,解决办法是使用自己的token认证(相当于去github上认证一下,挂个号,然后给你安装)。我检索了一圈,发现很多人出现这个问题,但中文网络中没有解决办法,捣鼓了一天终于解决了。问题如下 # 从github上安装森林图软件ggforestplot出现403报错 > devtools::install_github("NightingaleHealth/ggforestplot", build_vignettes = TRUE) Error: Failed to install 'unknown package' from GitHub: HTTP error 403. API rate limit exceeded for 175.29.122.76. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) Rate limit remaining: 0/60 Rate limit reset at: 2021-12-19 03:33:21 UTC To increase your GitHub API rate limit - Use `usethis::create_github_token()` to create a Personal Access Token. - Use `usethis::edit_r_environ()` and add the token as `GITHUB_PAT`.

发现是github的API rate限制,并且需要通过github token 提供GitHub API rate 限制,所以首先去github官网注册一个账号。然后在github的个人主页-settings-Developer settings-Personal access tokens-creat new token。具体步骤如下:

第一步:制备github token 1. 申请个人github账号,如果已经有账号登入就行,点击右上角个人图像,进去后点击下拉菜单中的settings。

在这里插入图片描述

2. 进去settings 后点击最下面的Developer settings

在这里插入图片描述

3. 点击Person access tokens, 点击右上角的Generate new token, 建立新的token

在这里插入图片描述

4. 首先命名你的token,可以随意写。然后选择token失效的时间,如果担心密码泄漏,可以选30天,30天后失效需要重新设置。我选的永久。最后勾选repo,token用于下载github上的代码仓库。点击generate token。

在这里插入图片描述 在这里插入图片描述

5. token 制备好了,记得拷贝形成的token密码,我的token密码是ghp_8h。。开头的,因为只出现一次,拷贝下来保存在记事本或者word中后续备用。

在这里插入图片描述

第二步, 在r中把token设置在环境变量中 1.打开rstudio 或者r,输入 usethis::edit_r_environ(),运行 > usethis::edit_r_environ() 2. 运行后,在代码区把第一次出现的token拷贝过去 GITHUB_TOKEN="ghp_8lNL22DYuvxnvODL6din7C9DdddTcQc"

我这个token是手输入的,可能不准确,实际使用中拷贝过去即可。保存,或者ctrl+s. 关闭r或者rstudio。

在这里插入图片描述

3. 重新打开rstudio,一定要关闭后重新打开,不然环境变量没加进去。重新安装发现可以正常安装。 > devtools::install_github("NightingaleHealth/ggforestplot") Using github PAT from envvar GITHUB_TOKEN Downloading GitHub repo NightingaleHealth/ggforestplot@HEAD These packages have more recent versions available. It is recommended to update all of them. Which would you like to update? 1: All 2: CRAN packages only 3: None 4: glue (1.5.0 -> 1.6.0 ) [CRAN] 5: withr (2.4.2 -> 2.4.3 ) [CRAN] 6: digest (0.6.28 -> 0.6.29) [CRAN] 7: cpp11 (0.4.1 -> 0.4.2 ) [CRAN] 8: stringi (1.7.5 -> 1.7.6 ) [CRAN] 9: backports (1.3.0 -> 1.4.1 ) [CRAN] Enter one or more numbers, or an empty line to skip updates: 1 glue (1.5.0 -> 1.6.0 ) [CRAN] withr (2.4.2 -> 2.4.3 ) [CRAN] digest (0.6.28 -> 0.6.29) [CRAN] cpp11 (0.4.1 -> 0.4.2 ) [CRAN] stringi (1.7.5 -> 1.7.6 ) [CRAN] yulab.utils (NA -> 0.0.4 ) [CRAN] gridGraphics (NA -> 0.5-1 ) [CRAN] tweenr (NA -> 0.3.3 ) [CRAN] Installing 12 packages: glue, withr, digest, cpp11, stringi, yulab.utils, gridGraphics, tweenr, backports, ggstance, ggplotify, ggforce There is a binary version available but the source version is later: binary source needs_compilation glue 1.5.1 1.6.0 TRUE Do you want to install from sources the package which needs compilation? (Yes/no/cancel) YES trying URL 'https://mirror.lzu.edu.cn/CRAN/bin/macosx/contrib/4.0/withr_2.4.3.tgz' Content type 'application/octet-stream' length 213991 bytes (208 KB) ================================================== downloaded 208 KB trying URL 'https://mirror.lzu.edu.cn/CRAN/bin/macosx/contrib/4.0/digest_0.6.29.tgz' Content type 'application/octet-stream' length 298444 bytes (291 KB) ================================================== downloaded 291 KB trying URL 'https://mirror.lzu.edu.cn/CRAN/bin/macosx/contrib/4.0/cpp11_0.4.2.tgz' Content type 'application/octet-stream' length 304354 bytes (297 KB) ================================================== downloaded 297 KB ...... 4. 测试包是否安装成功: > library(tidyverse) > library(ggforestplot) > # Get subset of example, linear associations, data frame > df_linear % + dplyr::arrange(name) %>% + dplyr::filter(dplyr::row_number() > # Forestplot > forestplot( + df = df_linear, + estimate = beta, + logodds = FALSE, + colour = trait, + title = "Associations to metabolic traits", + xlab = "1-SD increment in cardiometabolic trait + per 1-SD increment in biomarker concentration" + )

运行成功 在这里插入图片描述



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3